﻿using Dal;
using Model;

namespace Bll
{
    public class houseBll
    {
        private readonly houseDal dal;

        public houseBll(houseDal dal)
        {
            this.dal = dal;
        }

        /// <summary>
        /// 房型添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int HouseTypeAdd(houseModel info)
        {
            try
            {
                int list = dal.HouseSearchName(info.H_name);
                if(list > 0)
                {
                    return -1;
                }
                else
                {
                    int res = dal.HouseTypeAdd(info);
                    if(res > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -2;
                    }
                }
               
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 房型显示查询
        /// </summary>
        /// <param name="indexs"></param>
        /// <param name="counts"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public List<houseModel> HouseTypeList(out int indexs, out int counts, int pageindex = 1, int pagesize = 2)
        {
            try
            {
                return dal.HouseTypeList(out indexs, out counts, pageindex, pagesize);
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="h_id"></param>
        /// <returns></returns>
        public int DeleteInfo(int h_id)
        {
            try
            {
               return dal.DeleteInfo(h_id);
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="h_state"></param>
        /// <param name="h_id"></param>
        /// <returns></returns>
        public int UplowState(int h_state, int h_id)
        {
            try
            {
                return dal.UplowState(h_state, h_id);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}